package com.数据库MYSQL.JDBC连接;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

//JDBC的快速入门
public class JdbcConnection {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1.导入数据库驱动jar包( mysql-connector-java-5.1.37-bin.jar)
        //先复制,然后右键添加jar包

        //2.注册驱动
        Class.forName("com.mysql.jdbc.Driver");

        //3.获取数据库连接对象
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db3", "root", "nddwm");
        //Connection con=DriverManager.getConnection("jdbc:mysql:///db3","root","nddwm");

        //4.定义一个SQL语句
        String sql="update account set balance=2000 where id=1";

        //5.获取执行sql的对象,Statement
        Statement statement = connection.createStatement();

        //6.执行sql
        int count = statement.executeUpdate(sql);

        //7.处理结果
        System.out.println(count);

        //8.释放资源
        connection.close();
        statement.close();
        //DriverManager:驱动管理对象

        //connection:数据库连接对象

        //statement:执行sql的对象

        //resultset:结果集对象

        //preparedstatement:执行sql的对象,更加的强大



    }

}
